<div class="sim-body">
	<div class="sim-page inset">
		{$activity.content}
	</div>
	<div class="sim-page inset" id="register-page">
	    <empty name="registerInfo">
		<form id="form-register">
			<label class="sim-form-row">
				请输入您的姓名：
				<input type="text" class="sim-ipt sim-block" name="name" placeholder="您的姓名" data-error="姓名不能为空" />
			</label>
			<label class="sim-form-row">请输入您的手机：
				<input type="tel" class="sim-ipt sim-block" name="tel" placeholder="您的手机" data-error="手机号不能为空" />
			</label>
            <label class="sim-form-row">报名费用：
                <input type="text" class="sim-ipt sim-block" name="fee" value="{$activity.fee}" disabled="disabled" />
            </label>
			<label class="sim-form-row">
                <input type="hidden" name="cid" value="{$activity.cid}" />
                <input type="hidden" name="aid" value="{$activity.id}" />
                <input type="hidden" name="inviterId" value="{$inviterId}" />
                <input type="hidden" name="dg" value="1" />
				<button id="btn-register" type="button" class="sim-btn sim-btn-primary sim-block">我要报名</button>
			</label>
		</form>
		<else />
		<div>
		    <dl>
		        <dt>你已经报名，信息如下：</dt>
		        <dd>您的姓名：<span class="sim-label sim-label-royal">{$registerInfo.name}</span></dd>
		        <dd>您的电话：<span class="sim-label sim-label-royal">{$registerInfo.tel}</span></dd>
		        <gt name="activity.fee" value="0">
                <dd>报名费用：<eq name="registerInfo.pay" value="1"><span class="sim-label sim-label-success">已经支付</span><else /><span class="sim-label sim-label-danger">尚未支付</span></eq> </dd>
				</gt>
		    </dl>
		    <gt name="activity.fee" value="0">
            <eq name="registerInfo.pay" value="0">
                <button id="btn-pay" class="sim-btn sim-btn-primary sim-block">支付报名费</button>
            </eq>
            </gt>
		</div>
		</empty>
	</div>
	<div id="register-success" class="sim-page inset">
	
	</div>
</div>
<script type="text/javascript">
	$(function() {
		
	    $("#btn-pay").click(function() {
	        // 支付成功
	        $("#register-page").hide();
			/*$.ajax({
				type:"GET",
				url:"{$payUrl}",
				async:true,
				success: function(data) {
	       			 $("#register-success").html(data.extra.payForm);
				},
				error:function(){
				    simapp.toast("网络错误，请重试~");
				}
			}); // 异步提交支付*/
	        location.href = '{$payUrl}'; // 同步提交支付
	    });
	    
		$("#btn-register").click(function() {
		    $this = $(this);
		    var check = true;
		    
			$("form input[type='text'], form input[type='tel']").each(function() {
				var error = $(this).attr('data-error');
				if (error && $(this).val() == '') {
					simapp.toast(error);
					$(this).focus();
					check = false;
					return false;
				}
			});
			
			if(!check){
			    return false;
			}
			
			$.ajax({
				type:"POST",
				url:"__CONTROLLER__/ajaxRegister?debug",
				async:true,
				data: $("#form-register").serialize(),
				beforeSend: function(){
				    $this.attr('disabled');
				    simapp.toast("正在提交……");
				},
				success: function(data){
				    simapp.toast(data.msg);
				    if(data.state==1) {
				        // 支付成功
				        $("#register-page").hide();
				        if ( "{$activity.fee}"*1 > 0 ) {
							/*$.ajax({
								type:"GET",
								url:"{$payUrl}",
								async:true,
								success: function(data) {
					       			 $("#register-success").html(data.extra.payForm);
								},
								error:function(){
								    simapp.toast("网络错误，请重试~");
								}
							});*/ // 异步提交支付
					        location.href = '{$payUrl}'; // 同步提交支付
				        }
				    }
				},
				error:function(){
				    simapp.toast("网络错误，请重试~");
				},
				complete: function(){
				    $this.removeAttr('disabled');
				}
			});
		})
	});
</script>
